define(["jquery","vue",'common'],function ($,Vue,common){
    const Controller = {
        index:function (){
            var app = Vue.createApp({
                data(){
                    return {
                        //数据源
                        dataObj:{
                            total:0,
                            rows:[],
                            limit:10,
                            page:1
                        },
                        //多选数据
                        selectIds:[],
                        selectObj:[],
                        //搜索条件
                        seachObj:[
                            {
                                field:"custom",
                                value:null
                            },
                        ],
                        //主键
                        pk:"id",
                        imgType:[
                            'png',
                            'jpg',
                            'jpeg',
                            'gif',
                            'bmp',
                            'webp',
                            'svg',
                            'ico',
                        ],
                        select:0,
                        multiple:0,
                    }
                },
                created(){
                    this.indexLoadData()
                    let ob = this.getQueryParameterAsJson()
                    if(ob&&ob.select){
                        this.select = parseInt(ob.select)
                    }
                    if(ob&&ob.multiple){
                        this.multiple =parseInt( ob.multiple)
                    }
                    this.indexCreateHeight()
                    // console.log(ob,'ob')
                    // console.log(Config,'ccccccccccccccccc')
                },
                methods:{
                    ...common,
                    selectAttachment(row){
                        if(this.multiple!=1){
                            window.parent.callback(row.url)
                            let index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }else{
                            if(this.selectIds.indexOf(row.id)==-1){
                                this.selectIds.push(row.id)
                                this.selectObj.push(row)
                            }else{
                                this.selectIds.splice(this.selectIds.indexOf(row.id),1)
                                this.selectObj.splice(this.selectObj.indexOf(row),1)
                            }
                        }
                    },
                    selectNoAttachment(row){
                        if(this.selectIds.includes(row.id)==true){
                            this.selectIds.splice(this.selectIds.indexOf(row.id),1)
                            this.selectObj.splice(this.selectObj.indexOf(row),1)
                        }
                    },
                    confirmAttachment(){

                        let urls = []
                        if(this.selectObj.length>0){
                            this.selectObj.forEach(item=>{
                                urls.push(item.url)
                            })
                        }
                        window.parent.callback(urls)
                        let index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    }
                }
            })
            common.loadELEMENT(app,false)
            app.mount("#app");
        },
        add:function (){
            var app = Vue.createApp({
                data(){
                    return {
                        form:{
                            title:"",
                            content:"",
                            img:"",
                            status:1,
                            sort:0,
                            type:1,
                            url:"",
                            is_top:0,
                            is_hot:0,
                            is_recommend:0,
                            is_new:0,
                            is_best:0,
                        },
                        uploadurl:Config.upload.uploadurl
                    }
                },
                methods: {
                    onSubmit(){
                        window.parent.callback()
                        let index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    },
                    handleFileSuccess(response, file, fileList){
                        if(response.code==1){
                            window.parent.callback()
                            let index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }else{
                            this.$message({
                                message: response.msg,
                                type: 'error'
                            })
                        }
                    }
                }
            })
            common.loadELEMENT(app,false)
            
            app.mount("#app");
        }
    }
    return Controller;
})